﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CreateContinuousMFGFromCurve.CApCMCCreateContinuousMFGFromCurveEnabler
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.PrivateImplementationDetails;


namespace DnProcessSimulateCommands.CreateContinuousMFGFromCurve;

public class CApCMCCreateContinuousMFGFromCurveEnabler : ITxCommandEnabler
{
  public bool Enable => this.ShouldEnable();

  private bool ShouldEnable()
  {
    return TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded() && (this.GetSelectesItemsCount() == 0 || this.IsSelectionValid());
  }

  private int GetSelectesItemsCount() => TxApplication.ActiveSelection.TotalCount;

  private bool IsSelectionValid()
  {
    int selectesItemsCount = this.GetSelectesItemsCount();
    bool flag = true;
    TxTypeFilter txTypeFilter1 = new TxTypeFilter(new TxTypeFilter(new Type[5]
    {
      typeof (TxCurve),
      typeof (TxArc),
      typeof (TxPolyline),
      typeof (TxLine),
      typeof (Tx1DimensionalGeometry)
    }));
    if (TxTcUtilities.IsTcAnyPlatform)
    {
      TxTypeFilter txTypeFilter2 = new TxTypeFilter();
      foreach (Type allowedType in new CApCMCMfgContainerValidator().AllowedTypes)
      {
        txTypeFilter2.AddIncludedType(allowedType);
        txTypeFilter1.AddIncludedType(allowedType);
      }
      TxObjectList filteredItems1 = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter2);
      if (filteredItems1 != null)
        flag = ((Collection<ITxObject>) filteredItems1).Count <= 1;
      if (flag)
      {
        TxTypeFilter txTypeFilter3 = new TxTypeFilter();
        foreach (Type allowedType in new CApCMCOperationValidator("").AllowedTypes)
        {
          txTypeFilter3.AddIncludedType(allowedType);
          txTypeFilter1.AddIncludedType(allowedType);
        }
        TxObjectList filteredItems2 = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter3);
        if (filteredItems2 != null)
          flag = ((Collection<ITxObject>) filteredItems2).Count == 0 || ((Collection<ITxObject>) filteredItems2).Count == 1 && ((Collection<ITxObject>) filteredItems2)[0].CanBeModified;
      }
    }
    return flag && ((Collection<ITxObject>) TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) txTypeFilter1)).Count == selectesItemsCount;
  }
}
